package com.puzzlebazar.client.puzzleinfo;

import com.puzzlebazar.client.main.control.TabbedSubstate;
import com.puzzlebazar.client.main.view.TabbedView;

public class SolversSubstate extends TabbedSubstate {

	public static final String TAB_NAME = "Solvers";
	public static final String STATE_NAME = "Solvers";

	private final HistoryList historyList;

	private HistoryListView solversListView = null;
	
	public SolversSubstate( PuzzleInfoModel model, TabbedView view, PuzzleInfoController controller ) {
		super( view, controller );
		historyList = new HistoryList( null, model );
	}

	@Override
	public String getTabName() {
		return TAB_NAME;
	}

	@Override
	public String getStateName() {
		return STATE_NAME;
	}

	@Override
	public void enter() {
		super.enter();

		if( solversListView == null ) {
			solversListView = new HistoryListView( historyList, (PuzzleInfoController)controller );
		}
		historyList.setAutoRefresh( true );
		historyList.refresh();
		
		view.setMainWidget( solversListView );
	}

	@Override
	public void exit() {
		super.exit();
		historyList.setAutoRefresh( false );
	}

	@Override
	public void release() {
		super.release();
		if( solversListView != null )
			solversListView.release();
		solversListView = null;
		historyList.release();
	}

}
